<template>
  <view class="charging-start-box">
    <view class="charging-start-cantent-box">
      <view class="charging-start-background-image-box">
          <image class="charging-start-background-image" :src="cnd_path_image_prefix + '/start-charging-icon.gif'" />
      </view>
      <view class="charging-start-text">充电启动中...</view>
    </view>
  </view>
</template>

<script>
import { basic } from '../common/basicConfig'
import {chargeRecordDetailSepApi} from "../api/chargingManager/index"
export default {
  data(){
    return {
      cnd_path_image_prefix: basic.cnd_path_image_prefix,
      startChargeSeq: '',
      setTime: null
    }
  },
  onLoad(options){
    this.startChargeSeq = options.startChargeSeq || ''

    this.getChargeOrderData()

    this.setTime = setInterval(()=>{
      this.getChargeOrderData()
    },1000)
  },
  onUnload(){
    clearInterval(this.setTime)
    this.setTime= null
  },
  methods:{ 
    /**查询充电订单数据*/
    getChargeOrderData(){
      chargeRecordDetailSepApi({startChargeSeq: this.startChargeSeq}).then(res => {
        // chargeStatus : 0 : 启动中 ， 1： 正在充电 ， 2：结束充电 ， 3：订单异常
          const { connectorId, startChargeSeq, chargeStatus } = res.data
          if (chargeStatus == 1) {
            uni.redirectTo({
              url: `/pages/park/chargingManager/inProgress?connectorId=${connectorId}&startChargeSeq=${startChargeSeq}`
            })
          } 

          if (chargeStatus == 3) {
            uni.$u.toast('订单异常')
            this.hanglePagesredirectTo()
          }
      }).catch(err => {
        uni.$u.toast(err.data.msg)
        this.hanglePagesredirectTo()
      })
    },
    /**处理页面跳转*/
    hanglePagesredirectTo(){
      setTimeout(()=> {
        uni.redirectTo({
          url: `/pages/park/chargingManager/index`
        })
      },2500)
    },
  }
}
</script>

<style scoped>
.charging-start-box {
  padding-top: 20px;
  width: 100%;
  height: 100%;
  background: #557EFF;
  box-sizing: border-box;
}
.charging-start-cantent-box {
  padding-top: 126px;
  width: 100%;
  height: calc(100vh - 20px);
  background: #FFFFFF;
  border-radius: 24px 24px 0px 0px;
  opacity: 1;
  box-sizing: border-box;
}

.charging-start-background-image-box {
  margin: 0 auto;
  width: 200px;
  height: 200px;
}
.charging-start-background-image {
  width: 200px;
  height: 200px;
}
.charging-start-text {
  margin-top: 11px;
  text-align: center;
  font-size: 14px;
  font-weight: 400;
  color: #1A1A1A;
}
</style>